package thread.queue;

import java.util.Date;
import java.util.Map;
import java.util.Set;

public class PlusWorker extends Worker{

	public Object handle(Object input){
		Integer i = (Integer)input;
		return i*i*i;
	}
	
	public static void main(String[] args){
		System.out.println("开始时间" + new Date());
		Master m = new Master(new PlusWorker(),5);
		for( int i =0;i < 100000 ;i++){
			m.submit(i);	
		}
		m.execute();
		int re = 0;
		Map<String,Object> resultMap = m.getResultMap();
		while(resultMap.size() > 0 || !m.isComplete() ){
			Set<String> keys = resultMap.keySet();
			String key = null;
			for(String k : keys){
				key = k;
				break;
			}
			Integer i = null;
			if( key != null){
				i = (Integer)resultMap.get(key);
			}
			if( i != null ){
				re += i;
			}
			if( key != null ){
				resultMap.remove(key);
			}
		}
		System.out.println(re);
		
//		int re = 0;
//		for( int i=1;i <= 100000 ;i++){
//			re += i * i * i;
//		}
//		System.out.println(re);
		System.out.println("结束时间" + new Date());
	}
}
